#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>


/* button.h */
typedef struct {
	void (*press_down)(void);
	void (*press_up)(void);
	void (*press_repeat)(void);
	void (*single_click)(void);
	void (*double_click)(void);
	void (*press_long_start)(void);
	void (*press_long_repeat)(void);
} button_table_t;


/* button.c */
static button_table_t *p_button_table = NULL;

void button_register(button_table_t *callback)
{
	p_button_table = callback;
}

void button_process(void)
{
	//...

    if (p_button_table && p_button_table->press_down) {
        p_button_table->press_down();
    }

    //...

    if (p_button_table && p_button_table->press_up) {
        p_button_table->press_up();
    }

	//...
}


/* button_demo.h */


/* button_demo.c */
static void button_down_callback(void)
{
    printf("button_down_callback\r\n");
}
static void button_up_callback(void)
{
    printf("button_up_callback\r\n");
}
static void button_repeat_callback(void)
{
    printf("button_repeat_callback\r\n");
}
static void button_single_click_callback(void)
{
    printf("button_single_click_callback\r\n");
}
static void button_double_click_callback(void)
{
    printf("button_double_click_callback\r\n");
}
static void button_press_long_start_callback(void)
{
    printf("button_press_long_start_callback\r\n");
}
static void button_press_long_repeat_callback(void)
{
    printf("button_press_long_repeat_callback\r\n");
}

static const button_table_t button_table_callback =
{
    button_down_callback,
    button_up_callback,
    button_repeat_callback,
	button_single_click_callback,
	button_double_click_callback,
	button_press_long_start_callback,
	button_press_long_repeat_callback,
};


/* main.c */
int main(int argc, char *argv[])
{
    printf("Hello World!\r\n");


    button_register((button_table_t *)&button_table_callback);

    button_process();


    system("pause");
    return 0;
}
